package com.bright.ghj.overt.manager.impl;

import com.bright.ghj.overt.manager.FileListDFLZManager;
import com.bright.ghj.overt.pojo.po.primary.FileList;
import com.bright.ghj.overt.pojo.po.primary.FileListDFLZ;
import com.bright.ghj.overt.repository.primary.FileListDFLZRepository;
import com.bright.ghj.overt.repository.primary.FilelistRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Objects;

/**
 * @author Tz
 * @date 2024/01/22 15:03
 * @Description 上传到廉政配置表的Manager 实现
 */
@Component
@SuppressWarnings("all")
@RequiredArgsConstructor
public class FileListDFLZManagerImpl implements FileListDFLZManager {

    private final FileListDFLZRepository fileListDFLZRepository;

    private final FilelistRepository filelistRepository;

    /**
     * 根据账套类型查询账套需要上传廉政平台的报表
     *
     * @param ztTypeId 账套类型
     * @return         返回需要上传廉政的配置报表信息列表
     */
    @Override
    public List<FileListDFLZ> findCollectToGovernmentTableByZtTypeId(Integer ztTypeId) {
        //需要处理扩展字段的情况
        List<FileListDFLZ> collectToGovernmentTableByZtTypeId = fileListDFLZRepository.findCollectToGovernmentTableByZtTypeId(ztTypeId);
        for (FileListDFLZ fileListDFLZ : collectToGovernmentTableByZtTypeId) {
            //TODO 这里循环查表名不太好 最好一次性全部查寻出来
            FileList fileListByFileName = filelistRepository.getFileListByFileName(fileListDFLZ.getTableName());
            if (Objects.nonNull(fileListByFileName)) {
                fileListDFLZ.setTypeName(fileListByFileName.getFileType());
            }
        }
        return collectToGovernmentTableByZtTypeId;
    }
}
